package com.ylj.contact;

import android.app.ProgressDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;


/**
 * 加载进度条工具类 单例
 *
 * @version Revision: 0.0.1
 * @author: bangwei.yang
 * @Date: 2015-6-29
 */
public class LoadingDialog {

    private ProgressDialog mDialog = null;

    /**
     * 普通对话框
     *
     * @param context
     */
    public void show(Context context) {
        cancel();
        mDialog = new ProgressDialog(context, R.style.LodingDialog);
        mDialog.setCanceledOnTouchOutside(false);
        mDialog.setCancelable(true);
        try {
            mDialog.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
        View v = LayoutInflater.from(context).inflate(R.layout.dialog_progress, null);
        mDialog.setContentView(v);
    }

    /**
     * 自定义文字对话框
     *
     * @param context
     * @param message
     */
    public void show(Context context, String message) {
        cancel();
        mDialog = new ProgressDialog(context, R.style.LodingDialog);
        mDialog.setCanceledOnTouchOutside(false);
        mDialog.setCancelable(true);
        try {
            mDialog.show();
        } catch (Exception e) {
            e.printStackTrace();
        }

        View v = LayoutInflater.from(context).inflate(R.layout.dialog_progress, null);
        TextView txvMessage = (TextView) v.findViewById(R.id.txv_dialog_progress_content);
        mDialog.setContentView(v);
        txvMessage.setText(message);
    }

    /**
     * 强制显示等待框，无法取消，用户第三方登录，分享，支付等页面
     *
     * @param context
     */
    public void showLong(Context context) {
        cancel();
        mDialog = new ProgressDialog(context, R.style.LodingDialog);
        mDialog.setCanceledOnTouchOutside(false);
        mDialog.setCancelable(false);
        try {
            mDialog.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
        View v = LayoutInflater.from(context).inflate(R.layout.dialog_progress, null);
        mDialog.setContentView(v);
    }


    public void cancel() {
        if (mDialog != null&&mDialog.isShowing()) {
            mDialog.dismiss();
        }
    }

}
